package com.hyts.mvc.model;

import com.google.common.collect.Lists;
import com.hyts.mvc.config.BodyType;
import com.hyts.mvc.config.HandlerType;
import com.hyts.mvc.config.RequestMethod;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.List;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.mvc.model
 * author:Libo/Alex
 * create-date:2019-06-16 20:35
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: handler处理器数据模型对象
 */
@Builder
public final class HandlerWrapper {

    /**
     * 处理器类型
     */
    @Getter
    @Setter
    private HandlerType handlerType;

    /**
     * 处理器类型
     */
    @Getter
    @Setter
    private BodyType bodyType;

    /**
     * 请求方法类型
     */
    @Getter
    @Setter
    private RequestMethod requestMethod;

    /**
     * 处理器服务class类
     */
    @Getter
    @Setter
    private Class<?> clazz;

    /**
     * 执行的方法-反射方法
     */
    @Getter
    @Setter
    private Method executeMethod;

    /**
     * 执行方法句柄-代替反射提高性能
     */
    @Getter
    @Setter
    private MethodHandle executeMethodHandle;

    /**
     * 过滤、排除一些Interceptor
     */
    @Getter
    @Setter
    List<InterceptorWrapper> excludeInterceptor;


    public void getMethodHandle(Class<?> targetClazz,String methodName,Object[] args){

    }

    public static void main(String[] args) throws Throwable {
//        Class<?> clazz = MvcApplication.class;
//        Class<?> reClass = String.class;
//        Class[] clazzList = {String.class,String.class};
//        List<?> params = Lists.newArrayList("123","54");
//        try {
//            System.out.println(MethodHandles.lookup().findVirtual(clazz,"testMethod2",
//                    MethodType.methodType(reClass,clazzList)).invoke(MvcApplication.class.newInstance(),params.toArray()));
//           /* System.out.println(MethodHandles.lookup().findVirtual(String.class,"subString",
//                    MethodType.methodType(String.class,int.class,int.class)).invoke("1231231",0,1));*/
//        } catch (NoSuchMethodException | IllegalAccessException e) {
//            e.printStackTrace();
//        }
    }
}
